home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4388 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  45 lines

  1. Path: cad686.sc.intel.com!etse
  2. From: etse@scdt.intel.com (Eric Tse)
  3. Newsgroups: comp.lang.c++
  4. Subject: should operator== and operator= be virtual?
  5. Date: 30 Jan 1996 02:26:35 GMT
  6. Organization: Intel Santa Clara Design Technology
  7. Message-ID: <4ejvkr$btb@itnews.sc.intel.com>
  8. NNTP-Posting-Host: cad686.sc.intel.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hi,
  12.  
  13. Should operator==() and operator=() of a class be virtual if the class is
  14. planned for extensibility? Personally I think in general assignement 
  15. operators should be non-virtual, but I am not sure about equality operator.
  16. Could anyone helps? Thanks.
  17.  
  18. class A {
  19. public:
  20.   A& operator=(const A&);
  21.   virtual bool operator==(const A&) const;
  22.   virtual bool operator!=(const A&) const;
  23. };  
  24.  
  25. class B : public A {
  26. public:
  27.   B& operator=(const B&);
  28.   
  29.   virtual bool operator==(const A&) const; // ?
  30.   virtual bool operator!=(const A&) const; // ?
  31.  
  32.   virtual bool operator==(const B&) const; // ?
  33.   virtual bool operator!=(const B&) const; // ?
  34. };
  35.  
  36. Eric
  37.  
  38. --
  39. -----------------------------------------------------------------------------
  40. Eric Tse                     Design Technology, Microprocessor Products Group
  41. Intel Corporation                                  email: etse@scdt.intel.com
  42. M/S RN4-38, 2200 Mission College Blvd.                   phone: (408)765-8453
  43. Santa Clara, CA 95052                                      fax: (408)765-5278
  44. -----------------------------------------------------------------------------
  45.